#ifndef UTILS_H
#define UTILS_H

#include <sys/time.h>
#include <stdio.h>

//for MACROS
static struct timeval finalx_duration_start, finalx_duration_stop;
//for duration_start() and duration_stop();
static struct timeval finalx_duration_start_fun, finalx_duration_stop_fun;

#ifndef LOG_TAG
#define LOG_TAG "utils.h"
#endif //LOG_TAG

#define LOGD(...) printf( "<" LOG_TAG ">:" __VA_ARGS__); printf("\n");
#define LOGE(...) fprintf(stderr, "<" LOG_TAG ">:" __VA_ARGS__); fprintf(stderr, "\n");

#define _DURATION_COUNT(start,stop)\
    (((stop).tv_sec - (start).tv_sec) * 1000 + ((stop).tv_usec - (start).tv_usec) / 1000)

#define DURATION_START gettimeofday(&finalx_duration_start, NULL);

#define DURATION_STOP(ACTION_NAME) \
    gettimeofday(&finalx_duration_stop, NULL);\
    printf("<DURATION COUNT %s> using time: %lu milliseconds\n", (ACTION_NAME), _DURATION_COUNT(finalx_duration_start, finalx_duration_stop));

#define DUMP_IMAGE(img) \
    printf("%s with (%dx%d), widthStep=%d, depth=%d, nChannels=%d\n", #img, (img)->width, img->height, img->widthStep, img->depth, img->nChannels);
inline void duration_start() {gettimeofday(&finalx_duration_start_fun, NULL);}
inline unsigned long duration_stop()
{ gettimeofday(&finalx_duration_stop_fun, NULL); return _DURATION_COUNT(finalx_duration_start_fun, finalx_duration_stop_fun) ;}

#endif //UTILS_H
